package com.jar.exercise.java8新特性.StreamAPI;


import com.jar.exercise.java8新特性.方法的引用.Employee;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
 * 创建Stream
 * <p>
 * 创建一个Stream方式一：通过集合
 * <p>
 * 创建一个Stream方式二：Arrays.stream();
 * <p>
 * 创建一个Stream方式三：Stream.of(T... values)
 * <p>
 * 创建无限流
 * 迭代：Stream.iterate()
 * 生成：Stream.generate()
 */

public class TestStreamAPI1 {

/**
 * 创建一个Stream方式一：通过集合
 */

    @Test
    public void test1() {

        List<Employee> employee = Employee.getStudent();
        //顺序流
        Stream<Employee> stream = employee.stream();

        //并行流
        Stream<Employee> employeeStream = employee.parallelStream();

    }


/**
 * 创建一个Stream方式二：Arrays.stream();
 */

    @Test
    public void test2() {
        int[] ints = {1, 2, 3, 4, 6, 7};
        //调用Arrays类的 static <T> Stream<T> stream(T[] array)
        IntStream stream = Arrays.stream(ints);
        Employee employee1 = new Employee("张三","男", 12);
        Employee employee2 = new Employee("里斯","男", 13);

        Employee[] employees = {employee1, employee2};
        Stream<Employee> stream1 = Arrays.stream(employees);
    }


	/**
 * 创建一个Stream方式三：Stream.of(T... values)
	 */

    @Test
    public void test3() {
        Stream<Integer> integerStream = Stream.of(1, 1, 23, 55, 556, 664);
    }


	/**
 * 创建无限流
 * 迭代：Stream.iterate()
 * 生成：Stream.generate()
	 */

    @Test
    public void test4() {
        Stream.iterate(1, s -> s + 2).limit(5).forEach(System.out::println);
        Stream.generate(Math::random).limit(10).forEach(System.out::println);
    }
    @Test
    public void test5(){
    }
}

